define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dts/wages/wages/index' + location.search,
                    add_url: 'dts/wages/wages/add',
                    edit_url: 'dts/wages/wages/edit',
                    del_url: 'dts/wages/wages/del',
                    multi_url: 'dts/wages/wages/multi',
                    import_url: 'dts/wages/wages/import',
                    table: 'dts_wages',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'category', title: __('Category'), searchList: {"bar":__('Category bar'),"merits":__('Category merits')}, formatter: Table.api.formatter.normal},
                        {field: 'createby', title: __('Createby'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate', title: __('Operate'), 
                            table: table, events: Table.api.events.operate, 
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'details',
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-info btn-click',
                                    icon: 'fa fa-bitbucket',
                                    click: function (data, row) {
                                        Fast.api.open("dts/wages/"+row.category+"?ids="+row.id, row.title + " - 详情", {area:['80%','80%']});
                                    }
                                }
                                
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            $(".btn-download").click(function() {
                $(".btn-download").attr("disabled", true) //禁用
                window.open(Fast.api.fixurl('dts/wages/wages/download'));
                setTimeout(function() { $(".btn-download").attr("disabled", false) }, 5000);
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
